package com.overlord.im.server.mq.listener;

import com.google.common.base.Stopwatch;
import com.overlord.im.commons.message.OverlordImMessage;
import com.overlord.im.commons.mq.ListenerSelector;
import com.overlord.im.commons.mq.MqConstants;
import com.overlord.im.server.resolver.MessageResolver;
import com.overlord.im.server.resolver.message.MessageResolverFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @ClassName RedirectMessageListener
 * @Author wuwei
 * @Description NONE
 * @Date 2020/6/1 16:15
 **/
@Component
@Slf4j
public class RedirectMessageListener {

    @RabbitListener(queues = {
            MqConstants.OVERLORD_IM_MESSAGE_REDIRECT}, containerFactory = ListenerSelector.MULTI_THREAD)
    public void listener(OverlordImMessage message) {
        log.info("开始转发消息,参数:{}", message);
        Stopwatch stopwatch = Stopwatch.createStarted();
        switch (message.getMsgType()) {
            case SYSTEM:
                break;
            default:
                MessageResolver resolver = MessageResolverFactory.resolver(message);
                resolver.resolve(message);
        }
        stopwatch.stop();
        log.info("转发消息{}结束---耗时{}", message.getSequenceId(), stopwatch);
    }

}
